<%--
  Created by IntelliJ IDEA.
  User: 仁
  Date: 2021-03-25
  Time: 14:10
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/"/>
    <link rel="stylesheet" href="webjars/layui/2.5.5/css/layui.css">
</head>
<body>
<div class="layui-container">

    <script type="text/html" id="toolbar">
        <%--        <button type="button" class="layui-btn" id="tjin" onclick="add()">增加用户</button>--%>
    </script>

    <div class="layui-tab-item layui-show">
        <div class="layui-container">
            <div class="layui-collapse">
                <div class="layui-colla-item">
                    <div class="layui-colla-title">查询条件</div>
                    <div class="layui-colla-content layui-show">
                        <form class="layui-form layui-inline">
                            <div class="layui-inline">
                                <input type="text" class="layui-input" id="drugname" placeholder="根据药品名称进行查询">
                            </div>
                            <div class="layui-input-inline">
                                <button type="button" class="layui-btn" id="chaxun" onclick="search()" data-type="reload">查询</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <table id="storeTb" lay-filter="storeTb" ></table>
        </div>
    </div>

    <%--    <table  id="storeTb" lay-filter="storeTb"></table>--%>

    <%--修改和删除 id=active--%>
    <script type="text/html" id="active">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-input-block" style="margin-left: 0px">
                    <%--                    <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">--%>
                                        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">购买</button>
<%--                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">修改</button>--%>
                    <%--                    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" style="" lay-event="del" >删除</button>--%>
                </div>
            </div>
        </form>
    </script>




    <%--    修改功能--%>
    <div id="update" style="display: none">
        <form class="layui-form" lay-filter="updateForm"  style="padding: 50px" id="updateForm">
            <input  type="hidden" name="id" required  lay-verify="required" placeholder="隐藏id" autocomplete="off" class="layui-input">
            <div class="layui-form-item">
                <label class="layui-form-label">药品名称:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="drugname" required  lay-verify="required" placeholder="请输入药品名称" autocomplete="off" class="layui-input" disabled>
                </div>

                <label class="layui-form-label">厂商:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="changshang" required  lay-verify="required" placeholder="请输入生产厂商" autocomplete="off" class="layui-input" disabled>
                </div>

            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">单位:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="unit" required  lay-verify="required" autocomplete="off" class="layui-input" disabled>
                </div>

                <label class="layui-form-label">规格:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="guige" required  lay-verify="required"  autocomplete="off" class="layui-input" disabled>
                </div>

            </div>

            <%--            <div class="layui-form-item">--%>
            <%--               --%>
            <%--            </div>--%>

            <div class="layui-form-item">

                <label class="layui-form-label">销售价格:</label>
                <div class="layui-input-inline">
                    <input  type="number" name="price" required  lay-verify="required" placeholder="￥" autocomplete="off" class="layui-input" disabled>
                </div>

                <label class="layui-form-label">库存:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="count" required  lay-verify="required" placeholder="请输入库存" autocomplete="off" class="layui-input" disabled>
                </div>

            </div>

            <%--            <div class="layui-form-item">--%>
            <%--                --%>
            <%--            </div>--%>

            <div class="layui-form-item">
                <label class="layui-form-label">生产日期:</label>
                <div class="layui-input-inline">
                    <input  type="date" name="begindate" required  lay-verify="required" placeholder="请输入生产日期" autocomplete="off" class="layui-input" disabled>
                </div>

                <label class="layui-form-label">有效期至:</label>
                <div class="layui-input-inline">
                    <input  type="date" name="date" required  lay-verify="required" placeholder="请输入有效期至" autocomplete="off" class="layui-input" disabled>
                </div>
            </div>

            <%--            <div class="layui-form-item">--%>
            <%--               --%>
            <%--            </div>--%>

            <div class="layui-form-item">
                <label class="layui-form-label">批号:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="pihao" required  lay-verify="required" placeholder="请输入原批号" autocomplete="off" class="layui-input" disabled>
                </div>

                <label class="layui-form-label">购买数量:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="sum" required  lay-verify="required" placeholder="请输入购买数量" autocomplete="off" class="layui-input">
                </div>
            </div>
        </form>
    </div>
</div>
<script src="webjars/layui/2.5.5/layui.js"></script>
<script type="text/javascript">
    layui.use(["jquery","element","table","layer","form"],function () {
        let $=layui.jquery;
        let table=layui.table;
        let layer=layui.layer;
        table.render({
            id:'storeTb'
            ,elem: '#storeTb'
            ,url: '/store/searchAll' //数据接口0
            ,toolbar:"#toolbar"
            ,cols: [[ //表头\
                 {field: 'drugname', title: '药名',}
                ,{field: 'changshang', title: '厂商',align:"center",}
                ,{field: 'price', title: '销售价格',align:"center",}
                ,{field: 'begindate', title: '生产日期',}
                ,{field: 'date', title: '有效日期',}
                ,{field: 'pihao', title: '批号',}
                ,{field: 'beizhu', title: '备注', hide:true,}
                ,{field: 'location', title: '药品位置',}
                ,{field: 'count', title: '库存',align:"center"}
                ,{field: 'unit', title: '单位',align:"center"}
                ,{field: 'guige', title: '规格',align:"center"}
                ,{title: '操作',templet:"#active",align:"center",}
            ]],
            page:true
        });
        table.on("tool(storeTb)",function ({event,data}) {
            switch (event) {
                case "update":
                    // alert("修改")
                    update(data);
                    break;
                case "del":
                    // alert("删除")
                    del(data.id);
                    break;
            }
        })
    })

    //修改功能
    function update(data) {
        layui.use(["jquery","table","layer"],function () {
            let table=layui.table;
            let layer=layui.layer;
            let $=layui.jquery;
            $("#updateForm")[0].reset();
            layui.form.val("updateForm",data);
            // alert("过了")

            layer.open({
                type:1,
                content:$('#update'),
                area:["800px","465px"],
                btn:["购买","取消"],
                title:"购买药品",
                yes(){
                    let parms=  layui.form.val("updateForm")
                    $.post("/lingshou/add",parms)
                        // .done(({msg})=>{
                            table.reload("storeTb")
                            layer.close(layer.index);
                            layer.msg(msg)
                        // });
                },
            });
        })

    }

    //批量删除
    function delAll() {
        var data;
        var id=new Array();
        layui.use(["jquery","layer","table"],function () {
            let $=layui.jquery;
            let table=layui.table;
            let layer=layui.layer;
            //声明复选框
            datas =table.checkStatus("storeTb").data;
            // alert(datas)
            for(var i in datas) {
                id[i] = datas[i].id;//得到复选框的值
                // alert(id[i])
            }
            // alert(id)
            // 确认删除
            layer.confirm('确认删除选中的数据么？', {
                time: 20000, //20s后自动关闭
                btn: ['确定', '取消'],
                yes(){
                    //选中行的所有内容
                    $.ajax({
                        url:"/store/deleteAllStore",
                        type:"post",
                        data:JSON.stringify(id),
                        contentType:"application/json"
                    })
                        .done(function(result){
                            // alert(result.msg);
                            layui.layer.msg(result.msg);
                            layui.table.reload("storeTb");
                        });
                }
            });
        })
    }

    function search() {
        layui.use(["jquery","table","layer"],function () {
            let $=layui.jquery;
            let layer=layui.layer;
            let table=layui.table;
            let drugname=$("#drugname").val();
            let where={drugname,page: 1};
            table.reload("storeTb",{where})
        })
    }


</script>
</body>
</html>
